package org.suk.dp.strategy;

import java.text.MessageFormat;

/**
 * Description: 收费客户端<br/>
 * @version V1.0  2017/6/20 12:34  by 石冬冬(dongdong.shi@ucarinc.com) - Heil Hitler
 */
public class CashClient {
    /**
     * 单价
     */
    private double price;
    /**
     * 数量
     */
    private double number;

    public CashClient(double price, double number) {
        this.price = price;
        this.number = number;
    }

    /**
     * 客户端根据选择收费类型，计算总价=单价*数量
     * @param cashEnum
     * @return
     */
    public double compute(CashEnum cashEnum){
        CashContext context = null;
        switch (cashEnum){
            case NORMAL:
                context = new CashContext(new CashNormal());
                break;
            case REBATE:
                context = new CashContext(new CashRebate(0.8));
                break;
            case RETURN:
                context = new CashContext(new CashReturn(300,100));
                break;
        }
        return context.getResult(this.price * this.number);
    }

    public static void main(String[] args) {
        CashClient client = new CashClient(300,20);
        //循环迭代每一种收费类型
        for(CashEnum e : CashEnum.values()){
            System.out.println(MessageFormat.format("{0}，总价{1}￥",e.getDesc(),client.compute(e)));
        }
    }

    /**
     * 收费枚举
     */
    enum CashEnum{
        NORMAL("正常收费"),REBATE("打折收费"),RETURN("返利收费");

        CashEnum(String desc) {
            this.desc = desc;
        }

        private String desc;

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
    }
}
